package com.zzw.other;

import java.util.List;
import java.util.concurrent.TimeUnit;

public class ProcessDataThread implements Runnable {
	protected MySingnal singnal;
	private List<Integer> data;

	public ProcessDataThread(MySingnal singnal, List data) {
		this.singnal = singnal;
		this.data = data;
	}

	@Override
	public void run() {
		while (true) {
//			System.out.println(Thread.currentThread().getName() + "running");
			if (singnal.isHasDataToProcess()) {
				try {
					System.out.println(Thread.currentThread().getName() + " start!	 singnal: " + singnal.isHasDataToProcess());
					int x = data.get(0);
					int y = data.get(1);
					System.out.println("x: " + x + ", y: " + y + "  sum: " + (x + y));
					data.clear();
					singnal.setHasDataToProcess(false);
					TimeUnit.SECONDS.sleep(1);
					System.out.println(Thread.currentThread().getName() + " end!	 singnal: " + singnal.isHasDataToProcess());
				} catch (InterruptedException e) {
					System.out.println(Thread.currentThread().getName() + " is interrupted");
				}
			}
		}
	}

}
